﻿$(document).ready(function () {
    $('#datagrid').bootstrapTable({
        queryParams: queryParams,
        url: '/Member/Content/List?handler=Json',
        pagination: true,
        pageSize: 10,
        sidePagination: 'server',
        toolbar: '#gdtoolbar',
        showRefresh: true,
        showColumns: true,
        columns: [{
            checkbox: true
        }, {
            field: 'contentId',
            title: 'ID'
        }, {
            field: 'title',
            title: '标题',
            formatter: function (value, row, index) {
                return '[<a href="/Member/Content/List?categoryId=' + row.categoryId + '">' + row.categoryName + '</a>]<a href="/Member/Content/Modify/' + row.contentId + '">' + value + '</a>';
            }
        }, {
            field: 'moduleType',
            title: '类型',
            formatter: function (value, row, index) {
                switch (value) {
                    case 2:
                        return '文章';
                }
            }
        }, {
            field: 'inputer',
            title: '录入者'
        }, {
            field: 'hits',
            title: '点击数'
        }, {
            field: 'createTime',
            title: '创建时间'
        }, {
            field: 'status',
            title: '状态'
        }
        ]
    });

    //删除按钮
    $("#btn-del").click(function () {
        var checkRows = $('#datagrid').bootstrapTable('getSelections');
        if (checkRows.length == 0) BootstrapDialog.alert({
            title: '消息',
            message: '请选择要删除的内容',
            type: BootstrapDialog.TYPE_WARNING,
            buttonLabel: '确定'
        });
        else {
            BootstrapDialog.confirm({
                title: '确认',
                message: '确认删除已选的【' + checkRows.length + '】篇内容',
                type: BootstrapDialog.TYPE_DANGER,
                closable: true,
                draggable: true,
                btnCancelLabel: '取消',
                btnOKLabel: '删除',
                btnOKClass: 'btn-danger',
                callback: function (result) {
                    if (result) {
                        $.each(checkRows, function (index, value) {
                            $.post($("#btn-del").attr("data-ns-page"), { id: value.contentId, __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val() });
                        });
                        BootstrapDialog.alert({
                            title: '消息',
                            message: '成功删除完成',
                            type: BootstrapDialog.TYPE_WARNING,
                            closable: true,
                            draggable: true,
                            buttonLabel: '确定',
                            callback: function () {
                                $('#datagrid').bootstrapTable('refresh');
                            }
                        });
                    }
                }
            });
        }
    });
});